
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.Date;

public class SearchBug {
	public static void main(String[] args) throws Exception {
		String directoryString = "/home/dsw/workspaces/workspace07/operator";
		String regexString = ".*add.*request.*";
		regexString = ".*title.*iPrint.*";
		regexString = "(.*)(族群)(.*)";
		System.out.println("start ........");
		/* add pay */
		int count = 0;
		search2("/home/shewei.deng/catalina.out-20120727");

		// count = search(0, directoryString, regexString);
		System.out.println("共找到" + count + "个");
		System.out.println(new Date());
	}//result.txtttt1

	public static void search(String fileString) throws Exception {
		File file2= new File("/home/shewei.deng/resultttttt.txt");
		FileWriter fileWriter = new FileWriter(file2);
		BufferedWriter bw = new BufferedWriter(fileWriter);
		File file = new File(fileString);
		FileInputStream fis = new FileInputStream(file);
		InputStreamReader isr = new InputStreamReader(fis);
		BufferedReader br = new BufferedReader(isr);
		String back2 = "";
		String backStr = "";
		String currentStr = "";
		boolean flag =false;
		int i=0;
		while (null != (currentStr = br.readLine())) {
			i++;
			if(back2.contains("information")){
				flag=true;
			}
			if(flag){
				if(currentStr.contains("3451")){
					bw.write((i-2) + "::::::" + back2);
					bw.newLine();
					bw.write(i+":::" + currentStr);
					bw.newLine();
					bw.newLine();
					bw.flush();
					System.out.println((i-2) + "::::::" + back2);
					System.out.println(i+":::" + currentStr);
					System.out.println("\n\n\n");
				}
			}
			back2  =backStr;
			backStr = currentStr;
		}
		br.close();
		isr.close();
		fis.close();
		bw.flush();
		bw.close();
	}
	public static void search2(String fileString) throws Exception {
		File file2= new File("/home/shewei.deng/resultttttt.txt");
		FileWriter fileWriter = new FileWriter(file2);
		BufferedWriter bw = new BufferedWriter(fileWriter);
		File file = new File(fileString);
		FileInputStream fis = new FileInputStream(file);
		InputStreamReader isr = new InputStreamReader(fis);
		BufferedReader br = new BufferedReader(isr);
		String back2 = "";
		String backStr = "";
		String currentStr = "";
		boolean flag =false;
		int i=0;
		while (null != (currentStr = br.readLine())) {
			i++;
			if(back2.contains("information")){
				flag=true;
			}
			if(flag){
				if(currentStr.contains("3451")){
					bw.write((i-2) + "::::::" + back2);
					bw.newLine();
					bw.write(i+":::" + currentStr);
					bw.newLine();
					bw.newLine();
					bw.flush();
					System.out.println((i-2) + "::::::" + back2);
					System.out.println(i+":::" + currentStr);
					System.out.println("\n\n\n");
				}
			}
			back2  =backStr;
			backStr = currentStr;
		}
		br.close();
		isr.close();
		fis.close();
		bw.flush();
		bw.close();
	}
}